<template>
	<view class="SOdeliveryAddress">
		<u-navbar  title="提交订单"  :background="background" title-color="#FFF" back-icon-color="#fff"></u-navbar>
		<view class="SOdeliveryAddress-li">
			<view class="SOdeliveryAddress-li-l">
				配送地
			</view>
			<view class="SOdeliveryAddress-li-r" @click="distributionshow=true">
				<text class="SOdeliveryAddress-li-c">
					{{asaddresssInfo.ORMTB440CA14||''}}
				</text>
				<text class="iconfont iconarrow_right"></text>
			</view>
		</view>
		<view class="SOdeliveryAddress-li">
			<view class="SOdeliveryAddress-li-l">
				配送工地
			</view>
			<view class="SOdeliveryAddress-li-r" @click="workshow=true">
				<text class="SOdeliveryAddress-li-c">
					{{asaddresssInfo.ORMTB440CA16||''}}
				</text>
				<text class="iconfont iconarrow_right"></text>
			</view>
		</view>
		<view class="SOdeliveryAddress-li">
			<view class="SOdeliveryAddress-li-l">
				运费单价
			</view>
			<view class="SOdeliveryAddress-li-r">
				<text class="SOdeliveryAddress-li-c" v-if="AuthorizationOBJ.ORMTB417CA06==0">
					***元
				</text>
				<text class="SOdeliveryAddress-li-c" v-else>
					{{asaddresssInfo.ORMTB440CA21||0}}元
				</text>
			</view>
		</view>
		<view class="SOdeliveryAddress-li">
			<view class="SOdeliveryAddress-li-l">
				联系人
			</view>
			<view class="SOdeliveryAddress-li-r">
				<view class="SOdeliveryAddress-li-c">
					{{asaddresssInfo.iphoneName||''}}
				</view>
				<text>{{asaddresssInfo.iphone||''}}</text>
			</view>
		</view>
		<view class="SOdeliveryAddress-btn">
			<button type="default" @click="cancel">取消</button>
			<button type="default" @click="serve">确定</button>
		</view>
		<u-picker mode="selector" v-model="distributionshow" range-key="cateName" @confirm="distributionfirm" :default-selector="[0]" :range="distributionColumns"></u-picker>
		<u-picker mode="selector" v-model="workshow" range-key="cateName" @confirm="workfirm" :default-selector="[0]" :range="workColumns"></u-picker>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				userinfo:JSON.parse(uni.getStorageSync('userinfo')),
				background: {
					backgroundColor: '#00a1f1',
				},
				distributionshow:false,
				distributionColumns:[],
				workshow:false,
				workColumns:[],
				asaddresssInfo:{
					ORMTB440CA21:'',//派单运费
					ORMTB440CA13:'',//配送地ID
					ORMTB440CA14:'',//配送地名称
					ORMTB440CA15:'',//工地ID
					ORMTB440CA16:'',//工地名称
					iphoneName:'',//联系人
					iphone:'',//联系电话
				},
				value:'',
				AuthorizationOBJ:''
			}
		},
		onLoad(option) {
			if(this.userinfo.sign == 'CUS-3'){
				this.queryAuthorization()
			}
			this.value=option.value
			if(option.asaddresssInfo){
				var str=JSON.parse(option.asaddresssInfo)
				this.asaddresssInfo.ORMTB440CA21=str.ORMTB440CA21||''
				this.asaddresssInfo.ORMTB440CA13=str.ORMTB440CA13||''
				this.asaddresssInfo.ORMTB440CA14=str.ORMTB440CA14||''
				this.asaddresssInfo.ORMTB440CA15=str.ORMTB440CA15||''
				this.asaddresssInfo.ORMTB440CA16=str.ORMTB440CA16||''
				this.asaddresssInfo.iphoneName=str.iphoneName||''
				this.asaddresssInfo.iphone=str.iphone||''
			}
		},
		onShow() {
			this.distributionQuery()
		},
		methods:{
			queryAuthorization(){//查询子账户权限
				uni.showLoading({
					title: '加载中...',
					mask:true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb417/selectAccess/'+this.userinfo.ORMTB417ID, 
					method: 'GET',
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {	
							this.AuthorizationOBJ=res.data.data
						}else{
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon:false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon:false
						})
					}
				});
			},
			distributionfirm(e){
				this.asaddresssInfo.ORMTB440CA13=this.distributionColumns[e].id
				this.asaddresssInfo.ORMTB440CA14=this.distributionColumns[e].cateName
				this.workQuery()
			},
			serve(){
				if(this.asaddresssInfo.ORMTB440CA14==''){
					uni.showToast({
						title: '请选择配送地！！',
						duration: 5000,  
						icon: 'none',
					});
					return 
				}
				if(this.asaddresssInfo.ORMTB440CA16==''){
					uni.showToast({
						title: '请选择配送工地！！',
						duration: 5000,  
						icon: 'none',
					});
					return 
				}
				// var asaddresssInfo=JSON.stringify(this.asaddresssInfo)
				// uni.redirectTo({
				// 	url:'/pages/SOsubmit/index?value='+this.value+"&asaddresssInfo="+asaddresssInfo
				// })
				var obj={
					asaddresssInfo:this.asaddresssInfo,
					value:this.value,
				}
				obj=JSON.stringify(obj)
				uni.setStorageSync('obj', obj);
				uni.navigateBack({
				    delta:1
				});
			},
			cancel(){
				uni.navigateBack({
				    delta:1
				});
			},
			distributionQuery(){
				uni.showLoading({
				    title: '请求中...',
					mask:true
				});
				this.distributionColumns=[]
				var id
				if(this.userinfo.sign=='CUS-1'){
					id=this.userinfo.ORMTB400ID
				}else if(this.userinfo.sign=='CUS-2'||this.userinfo.sign == 'CUS-3'){
					id=this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb440/selectOrmtb404',
					method: 'POST',
					dataType: 'json',
					data:{
						ORMTBID:id,
						sign:this.userinfo.sign
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							var data=res.data.data
							data.forEach(item=>{
								this.distributionColumns.push({
									cateName: item.ORMTB404CA00,
									id: item.ORMTB404ID
								})
							})
							
						}else{
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon:false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon:false
						})
						uni.hideLoading();
					}
				});
			},
			workfirm(e){
				this.asaddresssInfo.ORMTB440CA15=this.workColumns[e].id
				this.asaddresssInfo.ORMTB440CA16=this.workColumns[e].cateName
				this.asaddresssInfo.ORMTB440CA21=this.workColumns[e].money
				this.asaddresssInfo.iphoneName=this.workColumns[e].iphonename
				this.asaddresssInfo.iphone=this.workColumns[e].iphone
			},
			workQuery(){
				uni.showLoading({
				    title: '请求中...',
					mask:true
				});
				this.workColumns=[]
				uni.request({
					url: this.baseUrl + '/orm/ormtb440/selectOrmtb405',
					method: 'POST',
					dataType: 'json',
					data:{
						ORMTBID:this.asaddresssInfo.ORMTB440CA13,
						sign:this.userinfo.sign
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							var data=res.data.data
							data.forEach(item=>{
								this.workColumns.push({
									cateName: item.ORMTB405CA00,
									id: item.ORMTB405ID,
									money:item.ORMTB405CA01,
									iphone:item.ORMTB405CA03,
									iphonename:item.ORMTB405CA02,
								})
							})
							
						}else{
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon:false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon:false
						})
						uni.hideLoading();
					}
				});
			},
		}
	}
</script>

<style scoped>
	.SOdeliveryAddress{
		width: 100vw;
		min-height: 100vh;
		background-color: #e3e3e3;
	}
	.SOdeliveryAddress-li{
		display: flex;
		justify-content: space-between;
		padding:30rpx 30rpx;
		font-size: 24rpx;
		color: #333;
		background-color: #FFF;
		border: 1px solid #e3e3e3;
	}
	.SOdeliveryAddress-li-l{
		color: #999;
		line-height: initial;
	}
	.SOdeliveryAddress-li-c{
		
	}
	.SOdeliveryAddress-li-r{
		flex: 1;
		text-align: right;
	}
	.SOdeliveryAddress-li .iconfont {
		font-size: 22rpx;
		margin-left: 10rpx;
		color: #333;
	}
	.SOdeliveryAddress-btn {
		margin-top: 70rpx;
		text-align: center;
	}
	.SOdeliveryAddress-btn button{
		display: inline-block;
		width: 200rpx;
		height: 70rpx;
		line-height: 70rpx;
		font-size: 30rpx;
		background-color: #ffaa00;
		color: #FFF;
	}
	.SOdeliveryAddress-btn button+button{
		margin-left: 20rpx;
		background-color: #00A1F1;
	}
</style>
